package com.probiz.estore.system.service.impl;

import java.util.List;

import com.probiz.estore.Constants;
import com.probiz.estore.common.model.system.Carrier;
import com.probiz.estore.core.service.impl.GenericManagerImpl;
import com.probiz.estore.system.dao.CarrierDao;
import com.probiz.estore.system.service.CarrierManager;

/**
 * Manager implementation for Carrier, responsible for business processing, and
 * communicate between web and persistence layer.
 */
public class CarrierManagerImpl extends GenericManagerImpl<Carrier> implements
		CarrierManager {

	private CarrierDao carrierDao = null;

	/**
	 * @param carrierDao
	 *            the carrierDao to set
	 */
	public void setCarrierDao(CarrierDao carrierDao) {
		this.carrierDao = carrierDao;
	}

	
	@Override
	protected void preDelete(Carrier entity) {
		
	}

	@Override
	protected void preSave(Carrier entity) {
		
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.core.service.impl.GenericManagerImpl#init()
	 */
	@Override
	protected void initManager() {
		dao = carrierDao;
	}

	public List<Carrier> findActiveCarriers() {
		return this.carrierDao.findActiveCarriers();
	}
	
	public Carrier getCarrierForEai() {
		return carrierDao.getCarrierForEai();
	}

	
	/*
	 * (non-Javadoc)
	 * @see com.probiz.estore.system.service.CarrierManager#deleteFully(com.probiz.estore.common.model.system.Carrier)
	 */
	public boolean deleteFully(Carrier carrier){
		if(carrier.getShippingMethods().size()>0){
			return false;
		}else{
			carrier.setDeleted(Constants.FLAG_TRUE);
			carrier.setStatus(Constants.FLAG_FALSE);
			save(carrier);
			return true;
		}
	}

}
